//
//  LBMEmoticonPopView.swift
//  EmoticonKeyboard
//
//  Created by 刘保满 on 16/6/1.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class LBMEmoticonPopView: UIView {

   
    @IBOutlet weak var emoticonBtn: LBMEmoticonButton!
    
    //提供一个类方法加载pop视图
    class func loadPopView() -> LBMEmoticonPopView {
        //加载xib文件
        let pop = NSBundle.mainBundle().loadNibNamed("LBMEmoticonPopView", owner: nil, options: nil).last as! LBMEmoticonPopView
    
        pop.backgroundColor = UIColor.clearColor()
        return pop
    }
    
    //pop显示的方法
    func show(btn: LBMEmoticonButton) {
        let window = UIApplication.sharedApplication().windows.last!
        
        if self.superview == nil {
            window.addSubview(self)
        }
        
        self.hidden = false
        
        //转换坐标
        let rect = btn.superview!.convertRect(btn.frame, toView: window)
        
        center.x = CGRectGetMidX(rect)
        
        frame.origin.y = CGRectGetMaxY(rect) - bounds.height
        //赋值
        emoticonBtn.em = btn.em

    }
    
    //隐藏pop方法
    func dismissAter() {
        
        let time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(Double(NSEC_PER_SEC)*0.2))
        dispatch_after(time_t,dispatch_get_main_queue()) {
            self.hidden = true
        }
        
    }
    
    
 
    
    
    
}
